//=============================================================================
/**
 * @file	opening_demo_local.h
 * @brief	オープニングデモ
 * @author	Nozomu Saito
 * @date    2009.03.20
 */
//=============================================================================

#ifndef __OPENING_DEMO_LOCAL_H__
#define __OPENING_DEMO_LOCAL_H__

#include "common.h"
#include "system/clact_tool.h" //for CLACT
#include "system/particle.h"	//for particle

#define PAL_ONE_SIZE	(2)		//２バイト
#define RESOURCE_NUM	(4)

#define RIVAL_MASK_NUM			(4)
#define ROCKET_BG_NUM			(3)

#define LEAF_NUM	(10)

#define MAP_BLOCK_MAX	(3)
#define ANIME_TYPE_NUM	(2)

#define S4_MONS_NUM	(3)

typedef enum{
	FADE_TYPE_IN,
	FADE_TYPE_OUT,
};

typedef enum{
	WIPE_WHITE_IN,
	WIPE_WHITE_OUT,
	WIPE_BLACK_IN,
	WIPE_BLACK_OUT,
};

typedef struct BLEND_WORK_tag
{
	u8 Counter;
	u8 BlendFrm;
	u8 Alpha;
	u8 End;
	TCB_PTR	Tcb;
	int MaskA;
	int MaskB;
	BOOL IsMain;
	int FadeType;
}BLEND_WORK;

typedef struct SCROLL_WORK_tag
{
	GF_BGL_INI * Bgl;
	BOOL Valid;
	int BgFrame;
	s16 Frm;
	u8 Counter;
	u8 End;
	TCB_PTR	Tcb;
	s16 OfsX;
	s16 OfsY;
	s16 OrgX;
	s16 OrgY;
}SCROLL_WORK;

typedef struct SCROLL_MANG_tag
{
	SCROLL_WORK Work[8];		//メイン・サブの4枚のＢＧ
}SCROLL_MANG;


typedef struct WND_PARAM_tag
{
	int SrcSX;
	int SrcSY;
	int SrcEX;
	int SrcEY;
	int DstSX;
	int DstSY;
	int DstEX;
	int DstEY;

	int InMask;
	int OutMask;
	u16 InEff;
	u16 OutEff;
}WND_PARAM;

typedef struct WND_WORK_tag
{
	BOOL Valid;
	BOOL IsMain;
	s16 Frm;
	u8 Counter;
	u8 End;
	TCB_PTR	Tcb;
	WND_PARAM Param;
	int NowSX;
	int NowSY;
	int NowEX;
	int NowEY;
}WND_WORK;

typedef struct WND_CNT_WORK_tag
{
	WND_WORK Work[2];	//メイン・サブで1つずつ
}WND_CNT_WORK;
/**
typedef struct SCRL_WND_WORK_tag
{
	GF_BGL_INI * Bgl;
	BOOL Valid;
	BOOL IsMain;
	int BgFrame;
	s16 Frm;
	u8 Counter;
	u8 End;
	TCB_PTR	Tcb;
	s16 SrcX;
	s16 SrcY;
	s16 DstX;
	s16 DstY;
	WND_PARAM Param;
}SCRL_WND_WORK;
*/
typedef struct ACT_MOVE_WORK_tag
{
	BOOL Valid;
	s16 Frm;
	u8 Counter;
	u8 End;
	TCB_PTR	Tcb;
	int OfsX;
	int OfsY;
	int OrgX;
	int OrgY;
	CLACT_WORK_PTR ActPtr;
	CLACT_WORK_PTR ActPtr2;
	CLACT_WORK_PTR ActPtr3;
}ACT_MOVE_WORK;

typedef struct WIPE_WORK_tag
{
	BOOL Valid;
	BOOL IsMain;
	TCB_PTR	Tcb;
	fx16 FX;
	fx16 FY;
	u8 Frm;
	u8 Counter;
	u8 End;
	u8 Type;
}WIPE_WORK;

typedef struct DISP_EFF_WORK_tag
{
	BLEND_WORK Blend;
	BLEND_WORK BlendSub;
	SCROLL_MANG ScrlMng;
	WND_CNT_WORK WndCnt;
	WIPE_WORK		WipeWork;
}DISP_EFF_WORK;

typedef struct BLK_3D_DATA_tag
{
	NNSG3dRenderObj			RenderObj;
	NNSG3dResFileHeader* ResFile;
	void *AnmMem[ANIME_TYPE_NUM];
	NNSG3dAnmObj* AnmObj[ANIME_TYPE_NUM];
}BLK_3D_DATA;

typedef struct SCENE3_3D_DATA_tag
{
	void			*TexFile;		//テクスチャーファイル実体へのポインタ
	NNSG3dResTex	*Texture;
	GF_CAMERA_PTR CameraPtr;		//カメラ
	BLK_3D_DATA	Block[MAP_BLOCK_MAX];
	GF_G3DMAN*		g3Dman;	// 3Dマネージャ
	NNSFndAllocator Allocator;
}SCENE3_3D_DATA;

typedef struct SCENE1_WORK_tag
{
	u8 Seq;
///	u8 SceneSeq;
	u8 InitOK;			//initシーケンス通過したか？
	u8 LoadOK;			//loadシーケンス通過したか？
///	u16 Wait;
	u8 dummy;
	u8 *SkipOKPtr;

	CLACT_U_RES_OBJ_PTR 	ResObjTbl[RESOURCE_NUM];		// リソースオブジェテーブル
	CLACT_WORK_PTR			SunMoon;
	CLACT_WORK_PTR			Mons;
}SCENE1_WORK;

typedef struct SCENE2_WORK_tag
{
	u8 Seq;
///	u8 SceneSeq;
	u8 InitOK;				//initシーケンス通過したか？
	u8 LoadOK;				//loadシーケンス通過したか？
	u8 NowLeafNo;
///	int Wait;

	CLACT_U_RES_OBJ_PTR 	ResObjTbl[2][RESOURCE_NUM];		// リソースオブジェテーブル
	CLACT_WORK_PTR			Hero;
	CLACT_WORK_PTR			Heroine;
	CLACT_WORK_PTR			Hero2;
	CLACT_WORK_PTR			Heroine2;
	CLACT_WORK_PTR			Hero3;
	CLACT_WORK_PTR			Heroine3;
	CLACT_WORK_PTR			Leaf[LEAF_NUM];
	ACT_MOVE_WORK			ActMvWk[2];
}SCENE2_WORK;

typedef struct SCENE3_WORK_tag
{
	u8 Seq;
///	u8 SceneSeq;
	u8 InitOK;			//initシーケンス通過したか？
	u8 LoadOK;			//loadシーケンス通過したか？
	u8 MaskNo;
	void *BgArc[RIVAL_MASK_NUM];
	void *SuikunBgArc;
	void *RocketBgArc[ROCKET_BG_NUM];
	NNSG2dScreenData *ScrnData[RIVAL_MASK_NUM];
	NNSG2dScreenData *SuikunScrnData;
	NNSG2dScreenData *RocketScrnData[ROCKET_BG_NUM];

///	u16 Wait;

	CLACT_U_RES_OBJ_PTR 	ResObjTbl[2][RESOURCE_NUM];		// リソースオブジェテーブル
	CLACT_WORK_PTR			Rival;
	CLACT_WORK_PTR			Minaki;
	CLACT_WORK_PTR			Ann[3];

	SCENE3_3D_DATA Data;
	int Disp3DNo;
}SCENE3_WORK;

typedef struct SCENE4_WORK_tag
{
	u8 Seq;
///	u8 SceneSeq;
	u8 InitOK;			//initシーケンス通過したか？
	u8 LoadOK;			//loadシーケンス通過したか？
	u8 dummy;

	CLACT_U_RES_OBJ_PTR 	ResObjTbl[S4_MONS_NUM+1][RESOURCE_NUM];		// リソースオブジェテーブル
	CLACT_WORK_PTR			HeroHand;
	CLACT_WORK_PTR			HeroineHand;
	CLACT_WORK_PTR			Flash;
	CLACT_WORK_PTR			Mons[S4_MONS_NUM];

	GF_G3DMAN*		g3Dman;	// 3Dマネージャ
	void *PtcHeap;
	PTC_PTR PtcPtr;

///	int Wait;
	BOOL MainDown;
	TCB_PTR	SwitchTcb;
}SCENE4_WORK;

typedef struct SCENE5_WORK_tag
{
	u8 Seq;
///	u8 SceneSeq;
	u8 InitOK;			//initシーケンス通過したか？
	u8 LoadOK;			//loadシーケンス通過したか？
	u8 dummy;
///	int Wait;
}SCENE5_WORK;

typedef struct OPENING_DEMO_WORK_tag * OPD_WK_PTR;


extern GF_BGL_INI *OPD_GetBGL(OPD_WK_PTR ptr);
extern DISP_EFF_WORK *GetDispEffWorkAdr(OPD_WK_PTR ptr);
extern const BOOL OPD_GetSkipFlg(OPD_WK_PTR ptr);
extern const int OPD_GetFrmCounter(OPD_WK_PTR ptr);
extern void OPD_ResetDispEff(OPD_WK_PTR ptr);

extern void OPD_InitResMan(OPD_WK_PTR wk, const u8 *tbl);
extern void OPD_DelResMan(OPD_WK_PTR wk);
extern CLACT_U_RES_MANAGER_PTR *OPD_GetResManPtr(OPD_WK_PTR wk);
extern void OPD_MakeClActHeader( const int inActID, OPD_WK_PTR wk,
								 const int inPriority,
								 const int inVramType,
								 CLACT_ADD *outAdd, CLACT_HEADER *outClActHeader);
extern void OPD_SetDispDistance( OPD_WK_PTR wk,
						  const int inMX, const int inMY,
						  const int inSX, const int inSY );
extern void OPD_StartDispAct(CLACT_WORK_PTR act, const u8 inFlg);

extern void OPD_SetAlphaBlend( 	BLEND_WORK * alpha_wk, const int inMaskA, const int inMaskB,
								const int inBldFrm, const int inFadeType, const BOOL inIsMain );

extern void OPD_ReqScroll(	GF_BGL_INI * ini, SCROLL_MANG *mng, const int inTarget,
							const s16 inXOfs, const s16 inYOfs,	const int inFrm );
extern void OPD_ReqScrollNorm(	GF_BGL_INI * ini, SCROLL_MANG *mng, const int inTarget,
						const s16 inXOfs, const s16 inYOfs,	const int inFrm );

extern BOOL OPD_CheckScrollEnd(SCROLL_MANG *mng, const int inTarget);
extern void OPD_StopScrollTcb(SCROLL_MANG *mng, const int inTarget);
extern WND_WORK * OPD_ReqWindowMove( WND_CNT_WORK *cnt_wk, const int inFrm,
									 const BOOL inIsMain, const WND_PARAM *inParam);
extern BOOL OPD_CheckWndEnd(WND_CNT_WORK *cnt_wk, const BOOL inIsMain);

extern void OPD_WipeStart( OPD_WK_PTR ptr, const u8 inWideCol, const BOOL inIsMain, const int inFrm );
extern BOOL OPD_CheckWipeEnd(OPD_WK_PTR ptr);

extern void OPD_IncSceneSeq(OPD_WK_PTR ptr);
extern u8 OPD_GetSceneSeq(OPD_WK_PTR ptr);
extern u8 OPD_GetSceneCount(OPD_WK_PTR ptr);

#endif	//__OPENING_DEMO_LOCAL_H__